package it.com.cci.observer_pattern.java_api;

import java.util.Observable;
import java.util.Observer;

/**
 * @author Lefnmg
 * @Description:
 * @date 2018/3/25
 */
public class CurrentCondationsDisplay implements Observer ,DispalyElement{
    Observable observable;
    private float temperature;
    private float humidity;

    public CurrentCondationsDisplay(Observable observable) {
        this.observable = observable;
        observable.addObserver(this);
    }

    @Override
    public void update(Observable obs, Object arg) {
        if (obs instanceof WeatherData){
            temperature = ((WeatherData) obs).getTemperature();
            humidity = ((WeatherData) obs).getHumidity();
            display();
        }
    }

    @Override
    public void display() {
        System.out.println("当前天气情况 ：" +"温度 "+temperature + "湿度 " + humidity);
    }
}
